package com.zx.kitchen.index.common.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.zx.kitchen.index.R;
import com.zx.kitchen.index.common.adapter.GoodsDayDetailAdapter;
import com.zx.kitchen.index.common.entity.GoodsDayDetailsBean;
import com.zx.kitchen.index.common.mvp.presenter.BusinessGoodsDayDetailPresenter;
import com.zx.kitchen.index.common.mvp.presenter.PurchaseGoodsDayDetailPresenter;
import com.zx.kitchen.index.common.mvp.view.GoodsDayDetailView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/21.
 */

public class GoodsDayDetailActivity extends Activity implements View.OnClickListener, GoodsDayDetailView {
    private String day;
    private String goods_id;
    private String goods_name;
    private ImageView toolbarLeft;
    private TextView toolbarTitle;
    private boolean isPurchase = false;
    private ListView mListView;
    private Button btnCount;
    private GoodsDayDetailAdapter mAdapter;
    private List<GoodsDayDetailsBean> mList = new ArrayList<>();
    private BusinessGoodsDayDetailPresenter businessGoodsDayDetailPresenter;
    private PurchaseGoodsDayDetailPresenter purchaseGoodsDayDetailPresenter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_goods_day_detail);
        day = getIntent().getStringExtra("day");
        goods_id = getIntent().getStringExtra("goods_id");
        goods_name = getIntent().getStringExtra("goods_name");

        initView();
        initListener();
    }

    private void initListener() {
        toolbarLeft.setOnClickListener(this);
        btnCount.setOnClickListener(this);
    }

    private void initView() {
        View view = findViewById(R.id.titleBar);
        toolbarLeft = (ImageView) view.findViewById(R.id.toolbar_leftLin);
        toolbarTitle = (TextView) view.findViewById(R.id.toolbar_title);
        toolbarTitle.setTextColor(getResources().getColor(R.color.blue));
        toolbarTitle.setText(goods_name);
        mListView = (ListView) findViewById(R.id.list_goods_day_detail);
        btnCount = (Button) findViewById(R.id.btn_count);
        mAdapter = new GoodsDayDetailAdapter(getBaseContext(), mList);
        mListView.setAdapter(mAdapter);
        businessGoodsDayDetailPresenter = new BusinessGoodsDayDetailPresenter(getBaseContext(), this);
        purchaseGoodsDayDetailPresenter = new PurchaseGoodsDayDetailPresenter(getBaseContext(),this);
        if (isPurchase){
            purchaseGoodsDayDetailPresenter.getFromNet(goods_id, day);
        }else {
            businessGoodsDayDetailPresenter.getFromNet(goods_id, day);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.toolbar_leftLin:
                finish();
                break;
            case R.id.btn_count:
                finish();
                break;
        }
    }

    @Override
    public void onSuccess(GoodsDayDetailsBean goodsDayDetailsBean) {
        if (null == goodsDayDetailsBean.getDetail()) return;
        mList.clear();
        mList.add(goodsDayDetailsBean);
        mAdapter.notifyDataSetChanged();

    }

    @Override
    public void onFail(String str) {

    }
}
